package com.kevin.model.jtable;

import java.util.Arrays;
import java.util.List;

import javax.swing.JTable;

import lombok.Data;

import com.kevin.model.db.DBTableColumnModel;
import com.kevin.util.Utils;

@Data
public class JTableColumnModel {

    public static final Integer COLINDEX_EXP_COLNAME = 3; // 下拉框的列号
    public static final Integer COLINDEX_JCB = 5; // 下拉框的列号
    public static final Integer COLINDEX_EXP_REMARKS = 6; // 下拉框的列号
    /** 可编辑列 */
    public static final List<Integer> COLINDEX_EDITABLE = Arrays.asList(COLINDEX_EXP_COLNAME, COLINDEX_JCB, COLINDEX_EXP_REMARKS);
    public static final String[] COLNAMES = { "序号", "表名", "字段名称", "导出名称", "数据库类型", "导成类型", "注释" };
    public static final Object[][] DEFAULTINFO = new Object[0][7];

    private Integer index; // 序号
    private String tableName; // 表名
    private String columnName; // 列字段名
    private String exportColName;// 导出字段名
    private String javaDataType; // 导出列类型
    private String columnType; // 列类型
    private String remarks; // 注释

    public static JTableColumnModel jTable2TableColModel(JTable jtable, int rowIndex) {
        String tableName = (String) jtable.getValueAt(rowIndex, 1); // 表名
        String tableColName = (String) jtable.getValueAt(rowIndex, 2);// 列名
        String exportColName = (String) jtable.getValueAt(rowIndex, 3); // 导出字段名
        String javaDataType = (String) jtable.getValueAt(rowIndex, 5);
        String remarks = (String) jtable.getValueAt(rowIndex, 6);// 列名
        JTableColumnModel dbTabColModel = new JTableColumnModel();
        dbTabColModel.setTableName(tableName);
        dbTabColModel.setColumnName(tableColName);
        dbTabColModel.setExportColName(exportColName);
        dbTabColModel.setJavaDataType(javaDataType);
        dbTabColModel.setRemarks(remarks);
        return dbTabColModel;

    }

    public static Object[] dbTableColModel2jTable(DBTableColumnModel tableColumn, int rowIndex) {
        String tableName = tableColumn.getTableName(); // 表名
        String tableColName = tableColumn.getColumnName();// 列名
        String columnTypeShow = tableColumn.getColumnTypeShow(); // 列类型展示
        String exportColName = tableColumn.getExportColName(); // 导出字段名
        String javaDataType = tableColumn.getJavaDataType();
        String remarks = tableColumn.getRemarks();// 列名
        return new Object[] { rowIndex + "", tableName, tableColName, exportColName, columnTypeShow, javaDataType,
                Utils.getStringValue(remarks) };

    }
}
